package controllers;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.event.AjaxBehaviorEvent;

import org.primefaces.event.RowEditEvent;
import org.primefaces.event.TransferEvent;
import org.primefaces.model.DualListModel;

import services.ComboBebidaXSalonService;
import services.SalonService;
import services.ComboBebidaService;
import modelo.Salon;
import modelo.Combobebida;
import modelo.Combobebidaxsalon;
import modelo.CombobebidaxsalonId;
import modelo.Servicioadicionalxsalon;

@ManagedBean(name="combobebidaxsalonBean")
@ViewScoped
public class ComboBebidaXSalonBean implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4237552358568778868L;
	
	@ManagedProperty("#{comboBebidaXSalonService}")
	private ComboBebidaXSalonService combobebidaxsalonService;
	private Combobebidaxsalon combobebidaxsalon = new Combobebidaxsalon();
	private float precio = 0;
	private Combobebidaxsalon combo = new Combobebidaxsalon();
	private List<Combobebidaxsalon> listComboBebidaXSalon = new ArrayList<Combobebidaxsalon>();
	private Combobebidaxsalon combobebidaxsalonSelected = new Combobebidaxsalon();
	
	@ManagedProperty("#{salonService}")
    private SalonService serviceSalon;
	private List<Salon> listSalones = new ArrayList<Salon>();
	private Salon selectedSalon=new Salon();
	
	@ManagedProperty("#{comboBebidaService}")
    private ComboBebidaService serviceComboBebida;
	private List<Combobebida> listComboBebida = new ArrayList<Combobebida>();
	private Combobebida selectedComboBebida = new Combobebida();
	
	public ComboBebidaXSalonBean() {
		super();
	}

	@PostConstruct
	public void init(){
		listComboBebida = serviceComboBebida.getListaComboBebida();
		listSalones = serviceSalon.getListaSalones();
		listComboBebidaXSalon = combobebidaxsalonService.getListacombobebidaxsalon();
	}

	public List<Salon> getListSalones() {
		return listSalones;
	}

	public void setListSalones(List<Salon> listSalones) {
		this.listSalones = listSalones;
	}

	public Salon getSelectedSalon() {
		return selectedSalon;
	}

	public void setSelectedSalon(Salon selectedSalon) {
		this.selectedSalon = selectedSalon;
	}

	public List<Combobebida> getListComboBebida() {
		return listComboBebida;
	}

	public void setListComboBebida(
			List<Combobebida> listComboBebida) {
		this.listComboBebida = listComboBebida;
	}

	public Combobebida getSelectedComboBebida() {
		return selectedComboBebida;
	}

	public void setSelectedComboBebida(
			Combobebida selectedComboBebida) {
		this.selectedComboBebida = selectedComboBebida;
	}

	public float getPrecio() {
		return precio;
	}

	public void setPrecio(float precio) {
		this.precio = precio;
	}
	
	public ComboBebidaXSalonService getCombobebidaxsalonService() {
		return combobebidaxsalonService;
	}
	public void setCombobebidaxsalonService(
			ComboBebidaXSalonService combobebidaxsalonService) {
		this.combobebidaxsalonService = combobebidaxsalonService;
	}

	public Combobebidaxsalon getCombobebidaxsalon() {
		return combobebidaxsalon;
	}

	public void setCombobebidaxsalon(
			Combobebidaxsalon combobebidaxsalon) {
		this.combobebidaxsalon = combobebidaxsalon;
	}

	public SalonService getServiceSalon() {
		return serviceSalon;
	}

	public void setServiceSalon(SalonService serviceSalon) {
		this.serviceSalon = serviceSalon;
	}

	public ComboBebidaService getServiceComboBebida() {
		return serviceComboBebida;
	}

	public void setServiceComboBebida(
			ComboBebidaService serviceComboBebida) {
		this.serviceComboBebida = serviceComboBebida;
	}

	public Combobebidaxsalon getCombo() {
		return combo;
	}

	public void setCombo(Combobebidaxsalon combo) {
		this.combo = combo;
	}

	public List<Combobebidaxsalon> getListComboBebidaXSalon() {
		return listComboBebidaXSalon;
	}

	public void setListComboBebidaXSalon(
			List<Combobebidaxsalon> listComboBebidaXSalon) {
		this.listComboBebidaXSalon = listComboBebidaXSalon;
	}
	
	public void agregarCombo() {
		combobebidaxsalon.setSalon(selectedSalon);
		combobebidaxsalon.setCombobebida(selectedComboBebida);
		listComboBebidaXSalon.add(combobebidaxsalon);
		combobebidaxsalon = new Combobebidaxsalon();
	}	
	
	public void eliminarCombo() {
		this.listComboBebidaXSalon.remove(combobebidaxsalonSelected);
	}

	public Combobebidaxsalon getCombobebidaxsalonSelected() {
		return combobebidaxsalonSelected;
	}

	public void setCombobebidaxsalonSelected(
			Combobebidaxsalon combobebidaxsalonSelected) {
		this.combobebidaxsalonSelected = combobebidaxsalonSelected;
	}
	
	public void guardarComboBebidaXSalon() throws Exception{
//		Combobebidaxsalon c = new Combobebidaxsalon();
//		combobebidaxsalon.setId(c.getId());
//		combobebidaxsalon.setSalon(selectedSalon);
//		combobebidaxsalon.setCombobebida(selectedComboBebida);
//		combobebidaxsalon.setPrecio(precio);
//		combobebidaxsalonService.guardarComboBebidaXSalon(combobebidaxsalon);
//		combobebidaxsalon = new Combobebidaxsalon();
		combobebidaxsalonService.guardarComboBebidaXSalon(selectedSalon, selectedComboBebida, combobebidaxsalon.getPrecio());
	}
	
}